package com.example.common;

public enum RstStatus {

    ok(200, "ok", "恭喜你，操作成功"),
    missParameter(101, "miss required parameter", "缺少必填参数"),
    invalidParameter(102, "parameter value invalid", "参数不合法"),
    noDataFound(103, "no data found", "对不起，没有找到相关数据"),
    noLogin(401, "no login", "对不起，请重新登录"),
    noPermission(402, "no permission", "对不起，您没有权限操作"),
    noPermissionR(700, "no permission", "禁止匿名访问，您没有权限操作"),
    loginOvertime(403, "login overtime", "登陆超时"),
    errorUrl(404, "errorUrl", "对不起，您输入的地址有误"),
    serviceError(500, "serviceError", "服务内部错误");


    private int code;
    private String msg;
    private String desc;

    RstStatus(int code, String msg, String desc) {
        this.code = code;
        this.msg = msg;
        this.desc = desc;
    }

    public static RstStatus getStatusByCode(int code) {
        for (RstStatus status : values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        return null;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static RstStatus getByCode(int code) {
        for (RstStatus status : values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        return null;
    }
}